package main;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;

import javax.swing.JApplet;

import controller.GameController;

import model.GameModel;
import model.entities.Direction;
import model.entities.LaserSource;
import model.entities.Mirror;
import model.entities.MirrorOrientation;
import model.entities.Wall;
import model.entities.targets.TransparentTarget;
import util.LevelUtils;
import view.test.GameBoardPanel;
import view.test.GlassPane;
import view.test.MainFrame;
import view.test.MainPanel;
import view.test.ViewBin;

public class MainApplet extends JApplet {
	
	private static final long serialVersionUID = 2657060690574931776L;
	
	public void init() {
	    try {
	        javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
	            public void run() {
	                createGUI();
	            }
	        });
	    } catch (Exception e) {
	        System.err.println("createGUI didn't successfully complete");
	    }
	}

	private void createGUI() {
		
		GameModel model = new GameModel();

		MainPanel mainPanel = new MainPanel();
		
		GlassPane glassPane = new GlassPane(new Dimension(800, 600));
		GameController controller = new GameController(model, mainPanel);
		GameBoardPanel panel = new GameBoardPanel(model, controller, glassPane);
		ViewBin viewBin = new ViewBin(controller, model, glassPane);
		
		mainPanel.setController(controller);
		mainPanel.setGameBoardPanel(panel);
		mainPanel.setViewBin(viewBin);
		mainPanel.setGlassPane(glassPane);
		
		mainPanel.setGameBoardPanel(panel);
		mainPanel.setViewBin(viewBin);
		
		model.registerWithModel(panel);
		
		this.add(mainPanel);
		this.setSize(800, 600);
		
		LevelUtils utils = new LevelUtils();
		try {
			utils.parseLevel(utils.getLevelNames()[0], model);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		String[] levelNameList = null;
		try {
			levelNameList = utils.getLevelNames();
		} catch (IOException e) {
			e.printStackTrace();
		}
		mainPanel.setLevelNameList(levelNameList);
		
		model.setDirty();
	}

}
